import requests
import json
import baozou_insert_sql
Platform = "王牌小说"
def wangpai():
    r = requests.session()
    # data = {
    #     'Basic Auth:{"",""}'
    # }
    header = {

        "authorization": "Basic bmFueHVuOnF3ZXJhc2RmNjY=",
        "content-length": "0",
        "origin": "https://backend.niuxs.cn",
        "referer": "https://backend.niuxs.cn/",
        "user-agent": "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.84 Safari/537.36"
    }
    rr =requests.post(url="https://api.niuxs.cn/oauth/token",data=data,headers = header)
    # print(rr.text)
    hh = json.loads(rr.text)
    token = hh["token"]
    # print(token)

    head = {
        "authorization": "Bearer {0}".format(token),
        "user-agent": "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.84 Safari/537.36"
    }
    aa = r.get(url="https://api.niuxs.cn/summary/daily/analysis",headers = head)
    # print(aa.text)
    html = json.loads(aa.text)
    date_time = html[1]["date"]
    Amount_share = int(html[1]["cashSum"])*0.9
    Amount_share = round(Amount_share, 2)
    baozou_insert_sql.baozou_spider_everyday_sum(date_time,Amount_share,Platform)
    # print(date_time,Amount_share)